﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Redirect404.Models;

namespace Redirect404.Services
{
    public class RedirectService : IRedirectService
    {
        [UsedImplicitly]
        private readonly IContentManager _contentManager;

        public RedirectService(IContentManager contentManager) {
            _contentManager = contentManager;
        }

        public IEnumerable<RedirectPart> Get() {
            return _contentManager.Query<RedirectPart, RedirectPartRecord>().Where(x => x.Id > 0).List();
        }

        public RedirectPart Get(int redirectPartId) {
            return _contentManager.Get<RedirectPart>(redirectPartId);
        }

        public void Delete(RedirectPart redirectPart) {
            _contentManager.Remove(redirectPart.ContentItem);
        }
    }
}